# -*- coding:utf8 -*- #
# -----------------------------------------------------------------------------------
# ProjectName:   smalleel-api-tools
# FileName:     signParams
# Author:
# Datetime:    2022/7/6 17:54
# Description：
# -----------------------------------------------------------------------------------
from common.util.md5Util.stringTomd5 import strTomd5


def sign_params(publicParams: dict, params: dict) -> str:
    """
        md5加密参数获取sign
    :param publicParams: 公共参数
    :param params: 字典参数
    :return: 加密后字段
    """
    params.update(publicParams)
    sortParams = dict(sorted(params.items(), reverse=False))
    valueLists = []
    for sortParamsKeys, sortParamsValues in sortParams.items():
        if isinstance(sortParamsValues, list):
            for sortParamsValue in sortParamsValues:
                valueLists.append(sortParamsValue)
                continue
        else:
            valueLists.append(sortParamsValues)
    signStr = ""
    for i in valueLists:
        signStr += str(i).strip()
    return strTomd5(signStr)
